/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* removeElements(struct ListNode* head, int val) {
    struct ListNode* prev = NULL, cur = head;
    while (cur)
    {
        if (cur->val == val)
        {
            if (cur == head)
            {
                head = cur->next;
                free(head);
                cur = head->next;

            }
            else
            {
                prev->next = cur->next;
                ferr(cur);
                cur = prev->next;
            }


        }
        else {
            prev = cur;
            cur = cur->next;



        }



    }
}